package com.kbbywyclient.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kbbywyclient.R;
import com.kbbywyclient.data.entity.MineScore;
import com.kbbywyclient.di.AppComponent;
import com.kbbywyclient.di.module.MineScoreModule;
import com.kbbywyclient.presenter.MineScorePresenter;
import com.kbbywyclient.ui.activity.base.BaseActivity;
import com.kbbywyclient.ui.contarct.MineScoreContract;
import com.kbbywyclient.util.ActivitySkipUtil;
import com.kbbywyclient.util.StringUtil;
import com.kbbywyclient.util.pre.PreUtils;
import com.kbbywyclient.widget.CustomToolBar;

import java.util.HashMap;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by cbb on 2017/4/21.
 * 我的积分
 */

public class MineScoreActivity extends BaseActivity implements MineScoreContract.View {
    @BindView(R.id.v_toolbar)
    CustomToolBar v_toolbar;
    @BindView(R.id.tv_surplus_score)
    TextView tv_surplus_score;//剩余积分
    @BindView(R.id.bt_score_recharge)
    Button bt_score_recharge;//积分充值
    @BindView(R.id.rl_score_detail)
    RelativeLayout rl_score_detail;//积分明细
    @BindView(R.id.tv_month_earn)
    TextView tv_month_earn;//本月赚
    @BindView(R.id.tv_month_expend)
    TextView tv_month_expend;//本月用

    @Inject
    MineScorePresenter presenter;

    private String CompanyID = "";
    private String CompanyTypeID = "";

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_mine_score;
    }

    @Override
    protected void initView() {
        v_toolbar.setLeftViewOnClickLinster(v -> finish());
    }

    @Override
    public void initData() {
    }

    @Override
    protected void onResume() {
        super.onResume();
        setScreenName("我的积分");
        presenter.getMineScoreInfo(String.valueOf(PreUtils.getUser(this).getSalesID()));
    }

    @Override
    public void initAppComponent(AppComponent appComponent) {
        appComponent.getMineScoreComponent(new MineScoreModule(this)).inject(this);
    }

    @OnClick({R.id.bt_score_recharge, R.id.rl_score_detail, R.id.rl_earn_score_way})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_score_recharge:
                HashMap<String, Object> map = new HashMap<>();
                map.put("CompanyID", CompanyID);
                map.put("CompanyTypeID", CompanyTypeID);
                ActivitySkipUtil.skipAnotherActivity(this, RechargeActivity.class, map);
                break;
            case R.id.rl_score_detail://积分明细
                ActivitySkipUtil.skipAnotherActivity(this, ScoreDetailActivity.class);
                break;
            case R.id.rl_earn_score_way://积分赚取方式
                ActivitySkipUtil.skipAnotherActivity(this, ScoreEarnActivity.class);
                break;
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("CompanyID", CompanyID);
        outState.putString("CompanyTypeID", CompanyTypeID);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        CompanyID = savedInstanceState.getString("CompanyID");
        CompanyTypeID = savedInstanceState.getString("CompanyTypeID");
    }

    @Override
    public void showLoadingDialog(String s) {
        showProgress(s);
    }

    @Override
    public void closeLoadingDialog() {
        dismissProgress();
    }

    @Override
    public void onGetMineScoreInfoSuccess(MineScore mineScore) {
        tv_surplus_score.setText(String.valueOf(mineScore.getScore()));
        if (StringUtil.isNotEmpty(mineScore.getThisMonthRewardScore() + "")) {
            tv_month_earn.setText("本月赚：" + mineScore.getThisMonthRewardScore());
        } else {
            tv_month_earn.setText("本月赚：0");
        }
        if (StringUtil.isNotEmpty(mineScore.getThisMonthBuyScore() + "")) {
            tv_month_expend.setText("本月用：" + mineScore.getThisMonthBuyScore());
        } else {
            tv_month_expend.setText("本月用：0");
        }

    }

    @Override
    public void onGetMineScoreInfoFailure() {

    }
}
